package cn.jacksigxu.min3halla.datagen;

import cn.jacksigxu.min3halla.MHMod;
import cn.jacksigxu.min3halla.init.MHItems;
import cn.jacksigxu.min3halla.recipe.builder.MixingRecipeBuilder;
import net.minecraft.data.PackOutput;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import net.minecraftforge.common.crafting.conditions.IConditionBuilder;

import java.util.function.Consumer;

public class ModRecipeProvider extends RecipeProvider implements IConditionBuilder {

    public ModRecipeProvider(PackOutput pOutput) {
        super(pOutput);
    }

    @Override
    protected void buildRecipes(Consumer<FinishedRecipe> pWriter) {

        // Drinks
        // Special
        specialMixing(pWriter, MHItems.A_FEDORA.get(), "a_fedora");
        specialMixing(pWriter, MHItems.ABSINTHE.get(), "absinthe");
        specialMixing(pWriter, MHItems.MULAN_TEA.get(), "mulan_tea");
        specialMixing(pWriter, MHItems.RUM.get(), "rum");

        // Vanilla
        MixingRecipeBuilder.builder(MHItems.BAD_TOUCH.get())
                .ingredients(0, 2, 2, 2, 4)
                .ice()
                .unlockedBy(getHasName(MHItems.BRONSON_EXTRACT.get()), has(MHItems.BRONSON_EXTRACT.get()))
                .save(pWriter, mixing("bad_touch"));
        MixingRecipeBuilder.builder(MHItems.BAD_TOUCH.get())
                .ingredients(0, 4, 4, 4, 8)
                .ice()
                .big()
                .unlockedBy(getHasName(MHItems.BRONSON_EXTRACT.get()), has(MHItems.BRONSON_EXTRACT.get()))
                .save(pWriter, mixing("bad_touch", true));

        MixingRecipeBuilder.builder(MHItems.SUGAR_RUSH.get())
                .ingredients(2, 0, 1, 0, -1)
                .unlockedBy(getHasName(MHItems.ADELHYDE.get()), has(MHItems.ADELHYDE.get()))
                .save(pWriter, mixing("sugar_rush"));
        MixingRecipeBuilder.builder(MHItems.SUGAR_RUSH.get())
                .ingredients(4, 0, 2, 0, -1)
                .big()
                .unlockedBy(getHasName(MHItems.ADELHYDE.get()), has(MHItems.ADELHYDE.get()))
                .save(pWriter, mixing("sugar_rush", true));

        // Original
        MixingRecipeBuilder.builder(MHItems.FOX_WINE.get())
                .ingredients(9, 4, 3, 0, 0)
                .ice()
                .age()
                .dye(Ingredient.of(Items.ORANGE_DYE))
                .unlockedBy(getHasName(MHItems.ADELHYDE.get()), has(MHItems.ADELHYDE.get()))
                .save(pWriter, mixing("fox_wine"));
    }

    public static void specialMixing(Consumer<FinishedRecipe> pWriter, ItemLike item, String name) {
        MixingRecipeBuilder.builder(item)
                .extra(Ingredient.of(item))
                .unlockedBy(getHasName(item), has(item))
                .save(pWriter, mixing(name));
    }

    public static ResourceLocation mixing(String name) {
        return mixing(name, false);
    }

    public static ResourceLocation mixing(String name, boolean big) {
        return MHMod.loc("mixing/" + name + (big ? "_big" : ""));
    }
}
